package com.tianhui.consignortwofei.pattern.orderStatus.status.impl;

import android.text.TextUtils;

import com.fgs.common.api.CommonConfig;
import com.fgs.common.utils.CheckUtil;
import com.tianhui.consignortwofei.api.OrderApiService;
import com.tianhui.consignortwofei.constant.OrderType;
import com.tianhui.consignortwofei.mvp.model.enty.OrderCondition;
import com.tianhui.consignortwofei.mvp.model.enty.OrderInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailItemInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailLineInfo;
import com.tianhui.consignortwofei.mvp.model.enty.detailItem.DetailRemarkInfo;
import com.tianhui.consignortwofei.pattern.orderStatus.status.IOrderStatus;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.reactivex.Observable;

/**
 * @author fgs
 * @date 2020/8/27
 * @description 外部单
 **/
public class ExternalStatus implements IOrderStatus {
    @Override
    public Observable getOrderListObservable(OrderCondition orderCondition) {
        Map<String, String> map = new HashMap<>();
        map.put("limit", "10");
        map.put("offset", "0");
        map.put("order", "desc");
        map.put("sort", "create_time");
        map.put("isstatus", "1");
        map.put("page", orderCondition.page + "");
        if (!TextUtils.isEmpty(orderCondition.searchKey)) {
            if (CheckUtil.isContainsNum(orderCondition.searchKey)) {
//                map.put("billno", orderCondition.searchKey);
                map.put("businessno", orderCondition.searchKey);
            } else {
//                map.put("destination", orderCondition.searchKey);
                map.put("salesmanusername", orderCondition.searchKey);
            }
        }
        return CommonConfig.getInstance().create(OrderApiService.class).externalList(map);
    }

    @Override
    public Observable getOrderDetailObservable(OrderCondition orderCondition) {
        Map<String, String> map = new HashMap<>();
        map.put("limit", "10");
        map.put("offset", "0");
        map.put("order", "desc");
        map.put("sort", "create_time");
        map.put("isstatus", "1");
        map.put("page", orderCondition.page + "");
        map.put("billno", orderCondition.billNo);
        return CommonConfig.getInstance().create(OrderApiService.class).externalList(map);
    }

    @Override
    public List getOrderDetailList(OrderInfo orderInfo) {
        List list = new ArrayList<>();

        DetailInfo detailInfo;
        DetailItemInfo detailItemInfo;
        DetailRemarkInfo remarkInfo;
        DetailLineInfo lineInfo;

        detailInfo = new DetailInfo();
        detailInfo.spanCount = 2;
        detailInfo.topLeftText = "货源单号：" + orderInfo.billno;
        detailInfo.topRightText = "发单人：" + orderInfo.placeusername;


        detailInfo.infoList = new ArrayList<>();
        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "数量：";
        detailItemInfo.content = orderInfo.quantity + "（件）";
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "最低价：";
        detailItemInfo.content = orderInfo.baseprice + "（元/吨）";
        detailInfo.infoList.add(detailItemInfo);


        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "初始重量：";
        detailItemInfo.content = orderInfo.weight + "（吨）";
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "金额：";
        detailItemInfo.content = orderInfo.totalprice + "（元）";
        detailInfo.infoList.add(detailItemInfo);

//        if (!TextUtils.isEmpty(orderInfo.detachweight)) {
            detailItemInfo = new DetailItemInfo();
            detailItemInfo.title = "拆单重量：";
            detailItemInfo.content = orderInfo.detachweight + "（吨）";
            detailInfo.infoList.add(detailItemInfo);
//        }

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "不含税：";
        detailItemInfo.content = orderInfo.baseprice+"（元/吨）";
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "剩余重量：";
        detailItemInfo.content = orderInfo.leftweight + "（吨）";
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "含税：";
        detailItemInfo.content = orderInfo.taxprice+"（元/吨）";
        detailInfo.infoList.add(detailItemInfo);

        detailInfo.bottomLeftText = "货物类型：" + orderInfo.goodstypetext;
        if (!TextUtils.isEmpty(orderInfo.detachable) && orderInfo.detachable.equals("1")) {
            detailInfo.bottomMiddleText = "可拆";
        } else {
            detailInfo.bottomMiddleText = "不可拆";
        }
        detailInfo.bottomRightText = "含税运输";

        list.add(detailInfo);

        lineInfo = new DetailLineInfo();
        list.add(lineInfo);

        detailInfo = new DetailInfo();
        detailInfo.title = "时间信息";
        detailInfo.isShowTitleTip = true;
        detailInfo.infoList = new ArrayList<>();
        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "创建时间：";
        detailItemInfo.content = orderInfo.create_time;
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "有效时间：";
        detailItemInfo.content = orderInfo.ordertruetime;
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "发单时间：";
        detailItemInfo.content = orderInfo.sendordertime;
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "装货截止时间：";
        detailItemInfo.content = orderInfo.lendtime;
        detailInfo.infoList.add(detailItemInfo);
        list.add(detailInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "预计卸车时间：";
//        detailItemInfo.content = orderInfo.recepittime;
        detailItemInfo.content = orderInfo.unloadearlhours + " 小时";
        detailInfo.infoList.add(detailItemInfo);
        list.add(detailInfo);

        lineInfo = new DetailLineInfo();
        list.add(lineInfo);

        detailInfo = new DetailInfo();
        detailInfo.title = "车辆信息";
        detailInfo.isShowTitleTip = true;
        detailInfo.infoList = new ArrayList<>();
        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "发送距离：";
        detailItemInfo.content = orderInfo.senddistance + "（km）";
        detailInfo.infoList.add(detailItemInfo);

        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "预计里程：";
//        detailItemInfo.content = "0（km）";
        detailItemInfo.content = orderInfo.senddistance + "（km）";
        detailInfo.infoList.add(detailItemInfo);

        String weightMax = orderInfo.weightmax;
        if (TextUtils.isEmpty(orderInfo.weightmax)) {
            weightMax = "不限";
        } else {
            weightMax = orderInfo.weightmax + "吨";
        }
        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "最大吨位：";
        detailItemInfo.content = weightMax;
        detailInfo.infoList.add(detailItemInfo);


        detailItemInfo = new DetailItemInfo();
        detailItemInfo.title = "车长：";
        String lengthMax = orderInfo.lengthmax;
        String lengthMin = orderInfo.lengthmin;
        if (TextUtils.isEmpty(lengthMax) && TextUtils.isEmpty(lengthMin)) {
            detailItemInfo.content = "不限";
        } else {
            detailItemInfo.content = lengthMin + "-" + lengthMax + "米";
        }

        detailInfo.infoList.add(detailItemInfo);
        list.add(detailInfo);

        lineInfo = new DetailLineInfo();
        list.add(lineInfo);

        remarkInfo = new DetailRemarkInfo();
        remarkInfo.title = "备注信息";
        remarkInfo.isShowTitleTip = true;
        remarkInfo.remark = orderInfo.remarks;
        list.add(remarkInfo);

        return list;
    }


    @Override
    public int getOrderStatusType() {
        return OrderType.TYPE_SOURCE;
    }

    @Override
    public String getOrderStatus(OrderInfo orderInfo) {
        String str = "状态：<font color='#FF0000'>" + orderInfo.isstatetext + "</font>";
        return str;
    }

    @Override
    public String getDispatchNumber(OrderInfo orderInfo) {
        return null;
    }

    @Override
    public String getFreight(OrderInfo orderInfo) {
        return null;
    }

    @Override
    public String getSearchHint() {
        return "按销售单号或销售员";
    }

    @Override
    public int getFeiOrderType() {
        return 0;
    }

}
